package com.salinity.kun.task;

import java.io.IOException;
import java.nio.file.Path;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.salinity.kun.helper.BaseHydrologyDataHelper;
import com.salinity.kun.helper.CalculationHelper;
import com.salinity.kun.helper.ConstantHelper;
import com.salinity.kun.model.FourierSeriesInput;
import com.salinity.kun.model.StationDateData;

/**
 * 计算马口站流量的傅里叶展开
 * 
 * @author Administrator
 *
 */
public class MakouFourierSeriesTask implements ITask {

	@Override
	public boolean run() throws IOException, ParseException {

		Path makouRawFilePath = ConstantHelper.getMakouRawFilePath();

		List<StationDateData> fluxDataList = BaseHydrologyDataHelper.getStationDateDataFromFile(makouRawFilePath);
		SimpleDateFormat sdf = ConstantHelper.getDefaultFormat();
		Date startDate = sdf.parse(ConstantHelper.getStartDate());
		Date endDate = sdf.parse(ConstantHelper.getEndDate());
		Double dT = ConstantHelper.getDT();
		Double T0 = ConstantHelper.getT0();
		int seriesCount = ConstantHelper.getSeriesCount();
		List<StationDateData> rsltDataList = BaseHydrologyDataHelper.doLinearInterpolation(fluxDataList, startDate, endDate, (int)(dT*60));
		String[] itemArray = ConstantHelper.getOutputItems();
		Path outputPath = ConstantHelper.getResultPath().resolve("ma_kou_fluxFS.csv").normalize();
		Double[] f = new Double[rsltDataList.size()];
		for (int i = 0; i < rsltDataList.size(); i++) {
			f[i] = rsltDataList.get(i).getValue();
		}
		FourierSeriesInput fourierSeriesInput = new FourierSeriesInput(T0, dT, f, seriesCount);

		CalculationHelper.writeToFile(fourierSeriesInput, itemArray, outputPath);

		return true;
	}

	public static void main(String[] args) {
		ITask makouFourierSeriesTask = new MakouFourierSeriesTask();
		try {
			makouFourierSeriesTask.run();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
